package com.seecen;

import com.seecen.entity.Emp;
import com.seecen.mapper.EmpMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws InterruptedException {
        // 1. 加载mybatis.xml
        InputStream inputStream = App.class.getClassLoader().getResourceAsStream("mybatis.xml");
        // 1.1 创建SqlSessionFactoryBuilder对象
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
        // 1.2 使用SqlSessionFactoryBuilder对象创建SqlSessionFactory对象
        SqlSessionFactory factory = sqlSessionFactoryBuilder.build(inputStream);
        // 1.3 使用SqlSessionFactory对象创建SqlSession对象

        for (int i = 0; i < 2; i++) {
            // 1.4 使用SqlSession对象执行增删改查
            // 获取代理对象
            SqlSession sqlSession = factory.openSession();
            EmpMapper mapper = sqlSession.getMapper(EmpMapper.class);
            Emp emp = new Emp();
            emp.setEmpno(7369);
            Emp queryEmp = mapper.findById(emp);
            System.out.println(queryEmp);
            sqlSession.close();
            System.out.println("分割线----------------");

        }


    }
}
